<template>
    <div class="login-wrap">
        <div class="ms-login">
            <div class="ms-title">律师与合同管理系统</div>

            <el-tabs type="border-card">
                <el-tab-pane>
                    <span slot="label"><i class="el-icon-date"></i> 用户名登录</span>
                    <el-form :model="param" :rules="rules" ref="login1" label-width="0px" class="ms-content">
                        <el-form-item prop="userName">
                            <el-input v-model="param.userName" placeholder="用户名">
                                <el-button slot="prepend" icon="el-icon-lx-people"></el-button>
                            </el-input>
                        </el-form-item>
                        <el-form-item prop="password">
                            <el-input
                                type="password"
                                placeholder="密码"
                                v-model="param.password"
                                @keyup.enter.native="submitForm()"
                            >
                                <el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
                            </el-input>
                        </el-form-item>
                        <div class="login-btn">
                            <el-button type="primary" @click="submitForm('login1')">登录</el-button>
                        </div>
                        <p class="login-tips">Tips : 用户名和密码随便填。</p>

                    </el-form>
                </el-tab-pane>
                <el-tab-pane label="手机号登录">
                    <el-form :model="param" :rules="rules" ref="login2" label-width="0px" class="ms-content">
                        <el-form-item prop="phoneNumber">
                            <el-input v-model="param.phoneNumber" placeholder="手机号">
                                <el-button slot="prepend" icon="el-icon-mobile"></el-button>
                            </el-input>
                        </el-form-item>
                        <el-form-item prop="password">
                            <el-input
                                type="password"
                                placeholder="密码"
                                v-model="param.password"
                                @keyup.enter.native="submitForm()"
                            >
                                <el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
                            </el-input>
                        </el-form-item>
                        <div class="login-btn">
                            <el-button type="primary" @click="submitForm('login2')">手机号登录</el-button>
                        </div>
                        <p class="login-tips">Tips : 密码默认手机号后六位。</p>

                    </el-form>

                </el-tab-pane>


                <el-tab-pane label="扫码登陆">
                    <el-form  label-width="0px" class="ms-content">
                        <div class='erweima'>
                            <p>请扫描二维码登录</p>
                            <img src='../../assets/img/hh.jpg'>
                        </div>


                    </el-form>
                </el-tab-pane>
            </el-tabs>







        </div>
    </div>
</template>

<script>
import { login } from "../../api/user"
export default {
    data: function() {
        return {
            param: {
                userName: '',
                password: '',
                phoneNumber:""
            },
            rules: {
                username: [{ required: true, message: '请输入用户名/手机号', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
                phoneNumber: [
                    { required: true, message: '请输入手机号', trigger: 'blur' },
                    {
                        pattern: /^1[3-9]\d{9}$/,
                        message: '请输入有效的手机号码',
                        trigger: 'blur'
                    }
                ]
            },


            activeName: 'second'
        };
    },
    methods: {
        submitForm(param) {
            this.$refs[param].validate(valid => {
                if (valid) {
                    console.log(this.param);
                    login(this.param).then(res=>{
                        console.log(res);
                        if(res.code==200) {
                            this.$message.success('登录成功');
                            localStorage.setItem("token",res.data.token)
                            localStorage.setItem('ms_username',JSON.stringify(res.data.user));
                            this.$router.push('/');
                        } else if(res.code==500){
                            this.$message.error('账号或密码有误');
                            return false;
                        }
                    })

                } else {
                    this.$message.error('请输入账号和密码');
                    // console.log('error submit!!');
                    return false;
                }
            });
        },
        handleClick(tab, event) {
            console.log(tab, event);
        }
    },
};
</script>

<style scoped>
.erweima {
    height: 176px;
}
.erweima img{
    margin: 0 37px;
    width: 170px;
    height: 170px;


}
.erweima p {
    padding-left: 59px;
}
.login-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    background-image: url(../../assets/img/login-bg.jpg);
    background-size: 100%;
}
.ms-title {
    width: 100%;
    line-height: 50px;
    text-align: center;
    font-size: 20px;
    color: #fff;
    border-bottom: 1px solid #ddd;
}
.ms-login {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 350px;
    margin: -190px 0 0 -175px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.3);
    overflow: hidden;
}
.ms-content {
    padding: 30px 30px;
}
.login-btn {
    text-align: center;
}
.login-btn button {
    width: 100%;
    height: 36px;
    margin-bottom: 10px;
}
.login-tips {
    font-size: 12px;
    line-height: 30px;
    color: #fff;
}
</style>